package com.asiainfo.cms.system.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.asiainfo.cms.system.entity.SysLogininfor;
import com.asiainfo.cms.system.mapper.SysLogininforMapper;
import com.asiainfo.cms.system.service.ISysLogininforService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 系统访问日志情况信息 服务层处理
 *
 * @author ruoyi
 */
@Service
public class SysLogininforServiceImpl implements ISysLogininforService {

    @Autowired
    private SysLogininforMapper logininforMapper;

    /**
     * 新增系统登录日志
     *
     * @param logininfor 访问日志对象
     */
    @Override
    public void insertLogininfor(SysLogininfor logininfor) {
        logininforMapper.insert(logininfor);
    }

    /**
     * 查询系统登录日志集合
     *
     * @param logininfor 访问日志对象
     * @return 登录记录集合
     */
    @Override
    public IPage<SysLogininfor> selectLogininforList(Page page, SysLogininfor logininfor) {
        QueryWrapper<SysLogininfor> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name", logininfor.getUserName());
        return logininforMapper.selectPage(page, wrapper);
    }

    /**
     * 批量删除系统登录日志
     *
     * @param infoIds 需要删除的登录日志ID
     * @return 结果
     */
    @Override
    public int deleteLogininforByIds(Long[] infoIds) {
        return logininforMapper.deleteBatchIds(CollectionUtil.toList(infoIds));
    }
}
